New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to restart kernel and run to current cell #6821
Conversation
Thanks for making a pull request to JupyterLab! To try out this branch on binder, follow this link: |
e5c58a7
to
bf9bfa8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @alesgenova, this is a really nice piece of work, and I think it's a useful option to have in the menu. One concern that I have is this: the mainmenu "semantic" commands are pretty specialized, and designed to be commands that are useful to more than one type of activity. So, "Restart and Run All" is, for instance, used by both the notebook and the text editor.
In this case, I think the command in question may be more relevant to just the notebook. In that case, we would want to implement the command similarly to how the "Run All Above" and "Run All Below" commands are implemented here:
jupyterlab/packages/notebook-extension/src/index.ts
Lines 1075 to 1115 in 079115d
commands.addCommand(CommandIDs.runAllAbove, { | |
label: 'Run All Above Selected Cell', | |
execute: args => { | |
const current = getCurrent(args); | |
if (current) { | |
const { context, content } = current; | |
return NotebookActions.runAllAbove(content, context.session); | |
} | |
}, | |
isEnabled: () => { | |
// Can't run above if there are multiple cells selected, | |
// or if we are at the top of the notebook. | |
return ( | |
isEnabledAndSingleSelected() && | |
tracker.currentWidget.content.activeCellIndex !== 0 | |
); | |
} | |
}); | |
commands.addCommand(CommandIDs.runAllBelow, { | |
label: 'Run Selected Cell and All Below', | |
execute: args => { | |
const current = getCurrent(args); | |
if (current) { | |
const { context, content } = current; | |
return NotebookActions.runAllBelow(content, context.session); | |
} | |
}, | |
isEnabled: () => { | |
// Can't run below if there are multiple cells selected, | |
// or if we are at the bottom of the notebook. | |
return ( | |
isEnabledAndSingleSelected() && | |
tracker.currentWidget.content.activeCellIndex !== | |
tracker.currentWidget.content.widgets.length - 1 | |
); | |
} | |
}); |
So it would be added as a more normal menu item, rather than using the specialized
ICodeRunner
interface. There is some more documentation discussing the differences between these approaches here
Alternatively, if we decide that this is appropriate for a semantic menu item, we would want to abstract it a bit further with a noun
for the thing-to-run (similar to how the "Run All" commands work above). Then it could interpolate the right noun for things that don't have cells to run.
What do you think @alesgenova?
@alesgenova - thanks again! What do you think of @ian-r-rose's comments above? |
@ian-r-rose I think we can consider this a fire and forget PR. Do you think this should be merged as is, or should it not be merged in its current state? |
I'm sorry for the delay in fixing the review comments, it's been hard to find the motivation to sit down and code during the sunny summer weekends. In case you don't want to merge it as is, I promise I'll find some time to address the problems during the upcoming cold weather in upstate NY! |
@alesgenova Just checking in on this. I may have the opportunity to have to get some help on this from our intern team at Cal Poly. But I wanted to check in with you first. Would you like help on finishing this off or would you prefer to leave it for you? |
@tgeorgeux I have been traveling and haven't had a chance to get back to this yet. |
Closing, since the feature has been implemented in #7789 |
References
Fixes #6746
Code changes
User-facing changes
A new entry is added to the "kernel" menu that reads "Restart Kkernel and Run up to Selected Cell".
Upon clicking, the kernel will be restarted, and all the cells above the current selection (and the current selection itself) will be run.
Before:
After:
Backwards-incompatible changes